// pages/refund/refund.js

const host = require('../../config.js').host;
const network = require('../../utils/network.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    balance:0,
    price:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  priceInput(e){
     
    this.setData({
      price:e.detail.value
    })
  },
  getInfo() {
    let that = this;
    network.requestGet(host + '/xcx/customer/getUserInfo', {}, res => {
       
      if (res.data.code == 200) {
        that.setData({
          balance: res.data.data.balance,
        })
      }
    })
  },
  postRefundData() {
    if(!this.data.price || this.data.price==0){
      wx.showToast({
        title: '请输入退款金额',
        icon:'none'
      })
      return;
    }
    if(this.data.price>this.data.balance){
      wx.showToast({
        title: '输入金额超过账户余额',
        icon:'none'
      })
      return;
    }
   
    let that = this;
    network.requestPost(host + '/weiXinPayment/refund', {
      "refundCount": that.data.price
    }, res => {
       
      if (res.data.code == 200) {
        wx.showToast({
          title: '申请已发起',
          duration: 2000 
        }) 
        setTimeout(() => {
          wx.navigateBack({
            delta: 1,
          })
        }, 2000);
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getInfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})